Repository navigation
Fix NPC crashes in combat AI - #284
Merged
Merged
Conversation
Port AI_FollowBehavior.CanSelectSchedule, NPC_MetroPolice combat schedule selection and AI_BaseNPC.GatherAttackConditions with the weapon line of sight checks. Spawning npc_gman or an armed npc_metropolice no longer throws NotImplementedException from the AI think.
Implement AI_TacticalServices.FindCoverPos/FindCoverNode and the AI_BaseNPC cover helpers (IsCoverPosition, IsValidCover, GetCoverActivity) so NPCs that take cover no longer crash.
Citizens and other NPCs relying on the base combat schedule selection crashed as soon as they acquired an enemy.
SelectCombatSchedule and GatherAttackConditions are not virtual in the SDK (NPC_MetroPolice hides SelectCombatSchedule), PlayerInSpread is. Track visited nodes in a stack buffer during the cover search like the pathfinder does.
so we get FLT_EPSILON
Contributor
Author
|
I think you forgot the ; 😭 |
ZehMatt
approved these changes
Nov 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spawning
npc_gman, an armednpc_metropolice, or anpc_citizenthat acquires an enemy crashed the game with aNotImplementedExceptionfrom the AI think. This ports the missing pieces from the 2013 SDK:AI_FollowBehavior:CanSelectSchedule,ShouldFollow,GetFollowTargetNPC_MetroPolice:SelectCombatSchedule,SelectScheduleNewEnemy,SelectScheduleArrestEnemy,SelectScheduleNoDirectEnemy,SelectRangeAttackSchedule,TryToEnterPistolSlot,AnnounceEnemyTypeAI_BaseNPC:SelectCombatSchedule,GatherAttackConditions,Range/MeleeAttack1/2Conditions,WeaponLOSCondition,CurrentWeaponLOSCondition,InnateWeaponLOSCondition,PlayerInSpread,IsWeaponStateChanging,IsCoverPosition,IsValidCover,GetCoverActivity,FearSound,UseAttackSquadSlotsBaseCombatWeapon.WeaponLOSConditionandWeaponLOSFilterAI_TacticalServices:FindCoverPos,FindCoverNode,GetNodePosRandSimTimer(CRandSimTimer) and theai_debug_shoot_positionsconvarNotes:
WeaponLOSFilterdoes not let traces pass through breakable glass yet,func_breakablehas no material type so far (left a todo).AI_Squad.GetLeaderis a stub like the rest ofAI_Squad. Squads are never created at the moment, so those paths are not reached.SelectCombatScheduleandGatherAttackConditionsare no longer virtual, matching the SDK (NPC_MetroPolicehidesSelectCombatSchedulethere too).Tested: all four configurations build and
Source.Common.Testspass. On gm_construct I spawned every entry of theNPC,Vehicles,SpawnableEntitiesandWeaponlists and used every tool mode: 2 crashes before (npc_gman,npc_metropolice), none after. Rebels against metro police for 25 seconds also run without any exception.